package com.jierui.meter.frontend.base.domain;


import java.io.Serializable;

import com.jierui.meter.frontend.base.enums.BusinessErrorEnum;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 通用返回对象
 * 
 */
@Getter
@Setter
@ToString
public class Response<T> implements Serializable {

	private static final long serialVersionUID = -6553522891216707934L;

	private String status;
	private String title;
	private String detail;
	private T result;

	/**
	 * 失败错误返回，只允许返回枚举中存在的类型，枚举中不存在先扩充枚举类
	 * @param respStatusEnum 枚举类型
	 */
	public Response(BusinessErrorEnum respStatusEnum) {
		this.status = respStatusEnum.getErrorCode();
		this.title = respStatusEnum.getErrorMessage();
	}
	
	public Response(String errorCode, String errorMessage, String detail) {
		this.status = errorCode;
		this.title = errorMessage;
		this.detail = detail;
	}

	/**
	 * 成功的返回
	 * @param t
	 */
	public Response(T t) {
		this.status = BusinessErrorEnum.SUCCESS.getErrorCode();
		this.title = BusinessErrorEnum.SUCCESS.getErrorMessage();
		this.result = t;
	}

	/**
	 * 成功的返回
	 */
	public Response() {
		this.status = BusinessErrorEnum.SUCCESS.getErrorCode();
		this.title = BusinessErrorEnum.SUCCESS.getErrorMessage();
	}

	public void setRespStatus(BusinessErrorEnum respStatusEnum) {
		this.status = respStatusEnum.getErrorCode();
		this.title = respStatusEnum.getErrorMessage();
	}
}
